<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=utf-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/css/plat-style.css"/>
</head>
<body>
<div class="layui-container">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" id="dailyForm">
                <input type="hidden" name="id" value="${daily.id}">
                <input type="hidden" name="position" value="${daily.position}">
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" autocomplete="off" class="layui-input" value="${daily.name}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>事件类型</label>
                    <div class="layui-input-block">
                        <select name="event" data-type="1">
                            <option value="${classify.url}" selected>${classify.name}</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>一级分类</label>
                    <div class="layui-input-block">
                        <select name="firstClass" data-type="1" data-click="10">
                            <option value="">请选择</option>
                            <c:forEach items="${firstList}" var="f">
                                <option value="${f.id}" ${daily.firstClass==f.id?'selected':''}>${f.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>二级分类</label>
                    <div class="layui-input-block">
                        <select name="secondClass" class="secondClass">
                            <%--<option value="">请选择</option>--%>
                            <c:forEach items="${secondList}" var="s">
                                <option value="${s.id}" ${daily.secondClass==s.id?'selected':''}>${s.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>图片</label>
                    <div class="layui-input-block">
                        <label for="imgUrl" class="layui-btn layui-btn-sm layui-btn-primary">上传图片</label>
                        <input accept=".jpg,.png,.gif,.jpeg" type="file" style="display:none;" name="imgUrl" id="imgUrl"
                               onchange="showImg(this)"/>
                        <img id="img" src="${daily.icon==null?' ':daily.icon}" width="${position.width}px" height="${position.height}px"/><br>
                        <span class="green">建议上传${position.width}*${position.height}尺寸大小的图片,格式支持jpg，png等</span>
                    </div>
                </div>
            </form>
            <div class="layui-form-item layui-layout-admin">
                <div class="layui-input-block">
                    <div class="layui-footer" style="left: 0;">
                        <button type="button" class="layui-btn"
                                onclick="FormSubmit('#dailyForm','/app/editDaily')">保存
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script src="/js/jquery/jquery.min.js"></script>
<script src="/js/jquery.form.js"></script>
<script src="/js/common.js"></script>
<script type="text/javascript" src="/js/plugins/image/previewImg.js"></script>
<script>
    layui.config({
        //静态资源所在路径
        base: '/layuiadmin/'
    }).extend({
        //主入口模块
        index: 'lib/index'
    }).use(['index', 'form'], function () {
        var $ = layui.$, layer = layui.layer, admin = layui.admin,
            element = layui.element, form = layui.form;
        element.render();
        form.on('select', function (data) {
            //获取原生DOM对象
            var dom = data.elem;
            var selectType = $(dom).data("type");
            var clickType = $(dom).data("click");
            var id = data.value;
            //获取事件下拉框被选中的'remark'值
            var remark = $(dom).find('option:selected').attr('remark');
            //'remark'值回显提示栏
            if (remark === " ") {
                $("#tip").text("");
            } else {
                $("#tip").text(remark);
            }
            if (selectType === 1){
                $.ajax({
                    url: "/classify/queryClassifyListByAjax",
                    data: {"pid": id,"type":3,"flag":2},
                    dataType: "json",
                    type: "post",
                    success: function (data) {
                        var html = '<option value="">请选择</option>';
                        $.each(data, function (i, v) {
                            html += '<option value="' + v.id + '" >' + v.name + '</option>'
                        });
                        $(".secondClass").append(html);
                        //重新渲染下拉框元素
                        form.render('select');
                    }
                });
            }
            if(clickType === 10){
                $(".secondClass").empty();
            }
        });
        form.render();
    });

    $(function () {
        //提示信息回显
        $("#tip").text($('select[name="event"]').find('option:selected').attr('remark'));
    });
</script>
</body>
</html>